package ejercicio_7;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;

public class Actividad_7_Ej_3y4 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		// Ejercicios 3 y 4

		Scanner sc = new Scanner(System.in);
		File f = new File("C:\\enteros.txt");
		String aux = "";
		int i = 0;
		int p = 0;
		boolean otro = false;
		ArrayList lista = new ArrayList();

		try {
			FileInputStream fileIn = new FileInputStream(f);
			DataInputStream dataIS = new DataInputStream(fileIn);

			while ((i = dataIS.read()) != -1) {
				// System.out.println((char) i);

				if (((char) i) != ';') {
					aux += (char) i;
					// System.out.println("AUX " + aux);

				} else if (((char) i) == ';') {
					lista.add(aux);
					aux = "";
				}

			}
			for (int j = 0; j < lista.size(); j++) {
				System.out.println(lista.get(j));
			}

		} catch (IOException e) {
		}

		try {
			FileOutputStream fileOut = new FileOutputStream("C:\\enteros.bin");
			DataOutputStream dataOS = new DataOutputStream(fileOut);

			try {
				for (int j = 0; j < lista.size(); j++) {
					System.out.println(lista.get(j));

					int auxiliar = (int) lista.get(j);

					dataOS.writeInt(auxiliar);
					System.out.println(auxiliar);

				}
			} catch (IOException e) {
			}

		} catch (FileNotFoundException e) {
		}
	}
}
